package com.yadang.stream;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: 亚当
 * @date: 2023年04月11日 21:46
 * @package: com.yadang.stream
 * @Description: TODO
 */
public class Test {
    public static void main(String[] args) {
        List<Product> list = getPruducts();
        // 将price相加
        BigDecimal reduce = list.stream().map(Product::getPrice).map(BigDecimal::new).reduce(BigDecimal.ZERO, BigDecimal::add);
        System.out.println(reduce);

        // 去重
        List<Product> collect = list.stream().distinct().collect(Collectors.toList());
        System.out.println(collect);
        /*for (int i = 0; i < list.size(); i++) {
            Product product = list.get(i);
            if ("2022-03-28".equals(product.getDate()) && "防脱育发液".equals(product.getName())){
                BigDecimal bigDecimal = new BigDecimal(product.getPrice());
                BigDecimal bigDecimal1 = bigDecimal.add(bigDecimal);
            }
        }*/
    }

    public static List<Product> getPruducts() {
        List<Product> list = new ArrayList<>();
        Product product = new Product();
        product.setColour("黄色");
        product.setDate("2022-02-19");
        product.setName("防脱育发液");
        product.setPrice("1000");

        Product product1 = new Product();
        product1.setColour("黄色");
        product1.setDate("2022-02-19");
        product1.setName("防脱育发液");
        product1.setPrice("1000");

        Product product2 = new Product();
        product2.setColour("黄色");
        product2.setDate("2022-02-19");
        product2.setName("防脱育发液");
        product2.setPrice("1000");
        list.add(product);
        list.add(product1);
        list.add(product2);
        return list;
    }
}
